package com.meta.platform.area.rest;

import com.meta.framework.core.CommonRes;
import com.meta.platform.area.io.AreaDistrictIo;
import com.meta.platform.area.io.Province;
import com.meta.platform.area.req.ListNextLevelAreaQry;
import com.meta.platform.area.service.AreasAppService;
import com.meta.platform.area.service.AreasQryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * area config rest api
 *
 * @Title:
 * @Package: com.metafnt.config.web.rest.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020/7/14 6:18 下午
 * @Version: v2.0
 */
@RestController
@RequestMapping("/area")
@Slf4j
public class ConfigAreaController {

	private AreasQryService areasQryService;

	@Autowired
	public ConfigAreaController(AreasAppService areasAppService, AreasQryService areasQryService) {
		this.areasQryService = areasQryService;
	}

	@ApiOperation(value = "获取省市区域集合(过滤失效地区)", notes = "获取省市区域集合(过滤失效地区)")
	@GetMapping("/listNextLevelArea")
	public CommonRes<List<AreaDistrictIo>> listNextLevelArea(ListNextLevelAreaQry listNextLevelAreaQry)
	{
		return CommonRes.success(areasQryService.listNextLevelArea(listNextLevelAreaQry.getParentId(), listNextLevelAreaQry.getKeyword()));
	}

	@ApiOperation(value = "获取所有省市区域集合(过滤失效地区)", notes = "获取所有省市区域集合(过滤失效地区)")
	@GetMapping("/listAllLevelArea")
	public CommonRes<List<Province>> listAllLevelArea(Integer level)
	{
		return CommonRes.success(areasQryService.listAllLevelArea(level));
	}

	@ApiOperation(value = "获取区县区域集合(过滤失效地区)", notes = "获取区县区域集合(过滤失效地区)")
	@GetMapping(value = "/queryDistrict/{cityId}")
	public CommonRes queryDistrict(@PathVariable Long cityId) {

		return CommonRes.success(areasQryService.listDistrict(cityId));
	}

	@ApiOperation(value = "获取区域信息(包含失效地区)", notes = "获取区域信息(包含失效地区)")
	@GetMapping(value = "/getAreaByAreaId/{areaId}")
	public CommonRes getAreaByAreaId(@PathVariable Long areaId) {
		
		return CommonRes.success(areasQryService.getAreaByAreaId(areaId));
	}
}
